<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台营销管理系统</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file='Public:header' />
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__ROOT__/public/js/html5shiv.js"></script>
    <![endif]-->
</head>

<body>
    <!--nav-->
<include file='Public:nav' />


<div class="container">
    <!--            <ul class="breadcrumb">
                    <li><a href="#">首页</a> <span class="divider">/</span></li>
                    <li><a href="#">Library</a> <span class="divider">/</span></li>
                    <li class="active">Data</li>
                </ul>-->
    <div class="page-header"><h4>修改密码</h4></div>

    <!--<p class="view"><b>功能：</b>管理&nbsp;|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加|&nbsp;添加</p>-->
    <div class="row">
        <div class="span12">
            <div class="pull-left">
                <php>if(session('admin')=='y'){</php>
                <a href="{:U('admin/list')}" class="btn btn-primary">管理员列表</a>&nbsp;&nbsp;
                <a href="{:U('admin/add')}" class="btn btn-primary">新 增</a>&nbsp;&nbsp;
                <php>}</php>
                <a class="btn btn-primary" onclick="history.go(-1);">返 回</a>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="span12" style="margin-top:10px;">
            <!--            <div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>登录成功！</div>-->
            <div id='pop'></div>
            <form class="form-horizontal" method="post">
                <fieldset>

                    <div id="legend" class="">
                        <legend class="">修改登录密码</legend>
                    </div>

                    <div class="control-group">

                        <!-- Text input-->
                        <label class="control-label" for="input01">当前密码</label>
                        <div class="controls">
                            <input type="password" placeholder="当前密码" name="user_pwd" class="input-xlarge">
                            <p class="help-block">请输入当前密码</p>
                        </div>
                    </div>

                    <div class="control-group">

                        <!-- Text input-->
                        <label class="control-label" for="input01">新密码</label>
                        <div class="controls">
                            <input type="password" placeholder="新密码" name="new_user_pwd" class="input-xlarge">
                            <p class="help-block">请输入新密码</p>
                        </div>
                    </div>

                    <div class="control-group">

                        <!-- Text input-->
                        <label class="control-label" for="input01">确认新密码</label>
                        <div class="controls">
                            <input type="password" placeholder="确认新密码" name="new_user_pwd1" class="input-xlarge">
                            <p class="help-block">请重复输入新密码</p>
                        </div>
                    </div>



                    <div class="form-actions">
                        <button type="button" class="btn btn-primary" id="save">保 存</button>&nbsp;&nbsp;
                        <a class="btn" href="{$pre_url}">返 回</a>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>
</div>





<include file='Public:footer' />
<script type="text/javascript">
$(function() {
    var user_pwd=$('[name=user_pwd]');
    var new_user_pwd=$('[name=new_user_pwd]');
    var new_user_pwd1=$('[name=new_user_pwd1]');
    $('#save').click(function() {
        if (check_fields()) {
            var data = $('form').serialize();
            $.ajax({
                type: "POST",
                url: app_url + "/user/update_password",
                data: data,
                dataType: 'json',
                cache: false,
                success: function(data) {
                    success(data);
                },
                error: function() {
                    error();
                }
            });
        }
    });
    
    
    function check_fields(){
        if(user_pwd.val()==''){
            success(0);
            return false;
        }
        
        if(new_user_pwd.val()==''){
            success(1);
            return false;
        }
        
        if(new_user_pwd.val()!=new_user_pwd1.val()){
            success(2);
            return false;
        }
        
        return true;
    }
    
    
    function pop_error(str){
        $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>'+str+'</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
    }
    
    

    $('#pop').ajaxStart(function() {
        $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                .fadeIn("slow");
    });

    function success(data) {
        switch(data){
            case 0:
                pop_error('请输入当前密码！');
                user_pwd.focus();
                break;
            case 1:
                pop_error('新密码不能为空，请填写新密码！');
                new_user_pwd.focus();
                break;
            case 2:
                pop_error('新密码两次输入的不一致，请重新输入！');
                new_user_pwd.val('');
                new_user_pwd1.val('');
                new_user_pwd.focus();
                break;
            case 3:
                pop_error('当前用户信息不存在！');
                location.href=app_url+"/main";
                break;
            case 5:
                $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>密码修改成功！</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
                user_pwd.val('');
                new_user_pwd.val('');
                new_user_pwd1.val('');
                break;
            case 4:
                pop_error('当前登录密码不正确！');
                user_pwd.val('');
                user_pwd.focus();
                break;
            case 6:
                pop_error('密码修改失败：当前密码与新密码相同，无需进行修改！');
                user_pwd.val('');
                new_user_pwd.val('');
                new_user_pwd1.val('');
                break;
        }
        
        
//        if (data.data == 1) {
//            $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>密码修改成功！</div>')
//                    .fadeIn("slow")
//                    .fadeOut(5000);
//        } else {
//            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>密码修改失败：新密码可能与当前密码相同！</div>')
//                    .fadeIn("slow")
//                    .fadeOut(5000);
//        }
    }


    function error() {
        $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                .fadeIn("slow")
                .fadeOut(5000);
    }
});
</script>
</body>
</html>
